package com.starbaba.system.user.view;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import javax.annotation.Resource;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert;

import com.google.gson.JsonObject;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;
import com.starbaba.common.ResultJson;
import com.starbaba.controllog.aop.LogAble;
import com.starbaba.controllog.model.ControlLogCategory;
import com.starbaba.core.hibernate.Page;
import com.starbaba.core.utils.IPUtil;
import com.starbaba.core.utils.MD5Encrypt;
import com.starbaba.core.utils.PkUtils;
import com.starbaba.core.utils.PropertyParamMapBuilder;
import com.starbaba.core.utils.Struts2Utils;
import com.starbaba.core.utils.json.JsonUtils;
import com.starbaba.core.web.constant.WebConstants;
import com.starbaba.core.web.page.PageResponse;
import com.starbaba.core.web.struts2.BaseAction;
import com.starbaba.core.web.struts2.JsonResult;
import com.starbaba.system.logaccess.model.LogAccessVO;
import com.starbaba.system.managelog.model.OperAction;
import com.starbaba.system.managelog.model.OperState;
import com.starbaba.system.user.dao.UserLoseStrategy;
import com.starbaba.system.user.model.ExtUserVO;
import com.starbaba.system.user.model.UserVO;
import com.starbaba.system.user.model.UserinfoVO;
import com.starbaba.system.user.model.getUserModel;
import com.starbaba.system.user.service.userService;
import com.starbaba.system.usergroup.model.UsergroupComidVO;
import com.starbaba.system.userofgroup.model.UserOfGroupVO;
import com.starbaba.tools.sequence.Sequence;
import com.tuanzi.server.loan_base.util.DateUtils;

@SuppressWarnings({"serial","rawtypes","unchecked"})
public class UserAction extends BaseAction implements ModelDriven {
	private Log logger = LogFactory.getLog(this.getClass());
	private static String passwd = "";
	private String flag = "TRUE";
	private static String defaultpassword = "123456";
	protected Object entityUserinfoVO;
	protected Object entityUserVO;
	protected Object entityUserLogVO;
	protected Object entityUserInfoLogVO;
	protected Object logUserInfoVO;
	protected UserinfoVO userinfoVO;
	
	
	@Resource(name="UserServiceImpl")
	private userService service;
	
	private getUserModel model;

	public Object getEntityUserVO() throws Exception {
		try {
			if (null == entityUserVO) {
				entityUserVO = UserVO.class.newInstance();
			}
		} catch (Exception ex) {
			throw new Exception(" voClass not fefinition or invalidate !");
		}
		return entityUserVO;
	}

	public Object getEntityUserinfoVO() throws Exception {
		try {
			if (null == entityUserinfoVO) {
				entityUserinfoVO = UserinfoVO.class.newInstance();
			}
		} catch (Exception ex) {
			throw new Exception(" voClass not fefinition or invalidate !");
		}
		return entityUserinfoVO;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	private ArrayList<ControlLogCategory> logCategorysArrayList;
	
	public UserAction() {
		this.voClass = UserVO.class;
		this.pkNameArray = new String[] { "userid" };
		// this.setSaveLog(true);
		logCategorysArrayList = new ArrayList<ControlLogCategory>();
	}
	
	public String showPage(){
		return "success";
	}

	@Override
	protected void beforeAdd() throws Exception {
		String startdate = DateUtils.getCurrentDate();
		paramsMap.put("startdate", startdate);
	
	}

	@Override
	protected void afterSave() throws Exception {
	}

	@Override
	protected void beforeSave() throws Exception {
		String sql = "from UserVO where userid = ?";
		String newUserId = (String)paramsMap.get("userid");
		ArrayList list = (ArrayList) this.getService().doFindByHQL(sql,
				new Object[] { newUserId });

		if (null != list && list.size() > 0) {
			throw new Exception("该用户已经存在");
		}

	}

	@Override
	@SuppressWarnings("finally")
	public String save() {
		Date accesstime = new Date();
		String ip = IPUtil.getClientIP(Struts2Utils.getRequest());
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils
				.getRequest(), paramsMap);
		String isNew = (String) paramsMap
				.get(WebConstants.PAGE_ATTRIBUTE_ISNEW);
		try {
			if (WebConstants.STRING_TRUE.equals(isNew)) {
				beforeSave();
				// 设置密码
				passwd = (String) paramsMap.get("passwd");
				if (passwd == null) {
					paramsMap.put("passwd", MD5Encrypt
							.getMD5Password(defaultpassword));
				} else {
					paramsMap.put("passwd", MD5Encrypt.getMD5Password(passwd));
				}
				
				String newUserId = (String) paramsMap.get("userid");
				// ((UserVO) getEntityVO()).setUserid(newUserId);
				paramsMap.put("userid", newUserId);
				// 保存多表数据时，需要作处理
				this.setParamsMapToTargetObject(paramsMap, getEntityUserVO());
				this.setParamsMapToTargetObject(paramsMap,
						getEntityUserinfoVO());

				((UserVO) getEntityUserVO()).setComid(userVO.getComid());
				((UserVO) getEntityUserVO()).setCreatetime(new Date());
				((UserVO) getEntityUserVO()).setCreator(userVO.getUserid());

				// 记录新增操作日志
				String oprType = (voClass == null) ? "unknown" : voClass.getSimpleName().toLowerCase().replaceFirst("vo$", "");
				logVO = this.getService().createAccesslogVO(userVO.getUserid(),accesstime, oprType, OperAction.INSERT, ip,null,this.getEntityUserVO(), OperState.SUCCESS);
				logUserInfoVO = this.getService().createAccesslogVO(userVO.getUserid(), accesstime, oprType,OperAction.INSERT, ip, null,this.getEntityUserinfoVO(), OperState.SUCCESS);

				entityUserLogVO = this.getService().doCreate(UserVO.class,this.getEntityUserVO(), LogAccessVO.class, logVO);
				entityUserInfoLogVO = this.getService().doCreate(UserinfoVO.class, this.getEntityUserinfoVO(),LogAccessVO.class, logUserInfoVO);

				this.addMessage("保存成功,该新用户密码为：123456！请及时更改！");
				afterSave();
			} else {
				beforeUpdate();
				this.setParamsMapToTargetObject(paramsMap, getEntityUserVO());
				this.setParamsMapToTargetObject(paramsMap,
						getEntityUserinfoVO());

				((UserVO) getEntityUserVO()).setLasttime(new Date());
				((UserVO) getEntityUserVO()).setLasteditor(userVO.getUserid());

				Object voOldUser = this.getService().doFindByPk(UserVO.class,PkUtils.getPkVO(UserVO.class, pkNameArray, paramsMap));
				Object voOldUserInfo = this.getService().doFindByPk(UserinfoVO.class,PkUtils.getPkVO(UserinfoVO.class, pkNameArray,paramsMap));

				// 记录更新操作日志
				String oprType = (voClass == null) ? "unknown" : voClass.getSimpleName().toLowerCase().replaceFirst("vo$", "");
				logVO = this.getService().createAccesslogVO(userVO.getUserid(), accesstime,oprType, OperAction.UPDATE, ip, voOldUser,this.getEntityUserVO(), OperState.SUCCESS);
				entityUserInfoLogVO = this.getService().createAccesslogVO(userVO.getUserid(), accesstime, oprType,OperAction.UPDATE, ip, voOldUserInfo,this.getEntityUserinfoVO(), OperState.SUCCESS);

				entityUserLogVO = this.getService().doUpdate(UserVO.class,this.getEntityUserVO(), LogAccessVO.class, logVO);
				entityUserInfoLogVO = this.getService().doUpdate(UserinfoVO.class, this.getEntityUserinfoVO(),LogAccessVO.class, entityUserInfoLogVO);

				this.addMessage("修改成功");
				afterUpdate();
				this.setIsEditAble(false);
				this.setIsNew(false);
			}

		} catch (Exception ex) {
			ex.printStackTrace();
			this.addErrorMessage("操作失败,失败原因:" + ex.getMessage());
			if (WebConstants.STRING_TRUE.equals(isNew)) {
				this.setIsNew(true);
				this.setIsEditAble(true);
				paramsMap.put("WebConstants.PAGE_ATTRIBUTE_ISNEW", "true");
			} else {
				this.setIsEditAble(true);
				this.setIsNew(true);
			}

			return Action.ERROR;
		} finally {
			try {
				this.setTargetObjectToParamsMap(entityUserVO, paramsMap);
				this.setTargetObjectToParamsMap(entityUserinfoVO, paramsMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return Action.SUCCESS;
		}

	}

	public String StatusLose() {
		JsonResult result = new JsonResult();
		try {
			paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(
					Struts2Utils.getRequest(), paramsMap);

			String pkValue = (String) paramsMap.get("userid");
			String optionType = (String) paramsMap.get("optionType");
			UserLoseStrategy strategy = new UserLoseStrategy(userVO, pkValue,
					optionType);
			this.getService().doProcess(strategy);
			result.setStatus("OK");
			result.setMessage("更新成功");
			sendJsonMessage(result);
			return null;
		} catch (Exception ex) {
			String errmsg = "操作失败,失败原因:" + ex.getMessage();
			log.error(errmsg, ex);
			result.setStatus("ERROR");
			result.setMessage(errmsg);
			try {
				sendJsonMessage(result);
			} catch (IOException e) {
				e.printStackTrace();
				log.error("信息返回失败:" + e.getMessage());
			}
			return null;
		}
	}

	@Override
	public String delete() {

		try {
			paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(
					Struts2Utils.getRequest(), paramsMap);
			String[] pkValues = this.getParamValueByParamsMap(paramsMap, "PK");
			beforeDelete();
			if (null != pkValues && pkValues.length > 0)
				for (int index = 0; index < pkValues.length; index++) {
					this.getService().doRemoveByPK(
							UserVO.class,
							PkUtils.getPkVO(UserVO.class,
									new String[] { "opercode" },
									pkValues[index]));
					this.getService().doRemoveByPK(
							voClass,
							PkUtils.getPkVO(voClass, pkNameArray,
									pkValues[index]));
				}
			afterDelete();
		} catch (Exception ex) {
			this.addErrorMessage(ex.getMessage());
			return Action.ERROR;
		}
		return Action.SUCCESS;
	}

	// 加载用户信息
	@Override
	public String edit() {
		try {
			paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(
					Struts2Utils.getRequest(), paramsMap);
			String pkValue = "";
			if (paramsMap.containsKey(WebConstants.REQUEST_ID)) {
				pkValue = (String) paramsMap
						.get(WebConstants.REQUEST_ID);
			}
			if (StringUtils.isNotBlank(pkValue)) {
				entityUserVO = this.getService().doFindByPk(UserVO.class,
						PkUtils.getPkVO(UserVO.class, pkNameArray, pkValue));
				entityUserinfoVO = this.getService().doFindByPk(
						UserinfoVO.class,
						PkUtils.getPkVO(UserVO.class,
								new String[] { "userid" }, pkValue));

			}
			beforeEdit();
			this.setTargetObjectToParamsMap(entityUserinfoVO, paramsMap);
			this.setTargetObjectToParamsMap(entityUserVO, paramsMap);
			this.setIsEditAble(true);
			this.setIsNew(false);
		} catch (Exception ex) {
			this.addErrorMessage(ex.getMessage());
			return Action.ERROR;
		}
		return Action.SUCCESS;
	}
	
	/**
	 * 
	 * @Title: addUser
	 * @Description: 【新增用户】
	 * @param
	 * @return 设定文件
	 * @return String 返回类型
	 * @throws
	 */
	@LogAble (operate=LogAble.OPERATE_ADD)
	public void addUser() {
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(
				Struts2Utils.getRequest(), paramsMap);
		paramsMap.put("passwd", MD5Encrypt.getMD5Password((String) paramsMap.get("password")));
		String userid = (String) paramsMap.get("userid");
		String truename = (String) paramsMap.get("username");
		String password = (String) paramsMap.get("passwd");
		String creator = (String) paramsMap.get("creator");
		String stopdate = (String) paramsMap.get("stopdate");
		String usergroup = (String) paramsMap.get("usergroup");
		String comid = String.valueOf(Sequence.getSequence());
		java.util.Date currentTime = new Date();
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
		java.util.Date stopTime = null;
		if(null == stopdate){
			Calendar endTime = Calendar.getInstance();
			endTime.setTime(currentTime);
			endTime.add(Calendar.YEAR,100);
			stopTime = endTime.getTime();
		}else{
			try {
				stopTime = format.parse(stopdate);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		try {
			//插入到user表
			UserVO entity = new UserVO();
			entity.setUserid(userid);	
			entity.setUsername(truename);
			entity.setPasswd(password);
			entity.setCreator(creator);
			entity.setLasteditor(creator);
			entity.setStartdate(currentTime);
			entity.setCreatetime(currentTime);
			entity.setLasttime(currentTime);
			entity.setStopdate(stopTime);
			//新增账户时默认设置为有效
			entity.setStatus("1");
			entity.setComid(comid);
			//新增用户时默认设置orgid为100010000
			entity.setOrgid("100010000");
			
			List list = this.getService().doFindByProperty(UserVO.class, "userid", userid);
			//如果已经有相同的userid,不允许增加
			if(list.size() > 0){
				sendErrMsg("已有同名账户");
			}else{
				Object ret = this.getService().doCreate(UserVO.class, entity);
				if (null == ret) {
					sendErrMsg("新增失败");	
				} else {
					
					//第二步,插入到user_of_group--新增时的组别权限
					if(null != usergroup){
						UserOfGroupVO entity1 = new UserOfGroupVO();
						UsergroupComidVO entity2 = new UsergroupComidVO();
						String[] usergroupList = usergroup.split("#");
						for (int index = 0; index < usergroupList.length; ++index) {
							entity1.setCreatetime(currentTime);
							entity1.setGroupid(Long.valueOf(usergroupList[index]));
							entity1.setUserid(userid);
							entity1.setCreator(creator);
							Object ret1 = this.getService().doCreate(UserOfGroupVO.class, entity1);
							if (null == ret1) {
								sendErrMsg("新增权限失败");
							}else{
                                //插入到UsergroupComidVO
								entity2.setComid(comid);
								entity2.setGroupid(Long.valueOf(usergroupList[index]));
								Object ret2 = this.getService().doCreate(UsergroupComidVO.class, entity2);
								if (null == ret2) {
									sendErrMsg("新增权限失败");
								}else{
									if(getLastTimeAddAction(usergroupList.length, index)){
										JsonObject result = new JsonObject();
										ResultJson resultJs = new ResultJson();
										resultJs.msg = "新增成功";
										result.add("result", resultJs.toJSON());
										sendJsonMessage(result.toString());
										
										ControlLogCategory logCategory = new ControlLogCategory();
										logCategory.setId(userid);
										logCategory.setName(truename);
										logCategorysArrayList.add(logCategory);
									}
								}
							}
						}
					}else{
						//如果新增时用户组别权限为空,直接返回信息
						sendErrMsg("用户组别权限为空,请后续自行添加");
					}

				}		
			}	
		} catch (Exception e) {
			sendErrMsg(e.getMessage());
		}

	}
	
	/**
	 * 
	 * @Title: deleteUser
	 * @Description: 【注销】
	 * @param
	 * @return 设定文件
	 * @return String 返回类型
	 * @throws
	 */
	@LogAble (operate=LogAble.OPERATE_MODIFY)
	public void deleteUser(){
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(
				Struts2Utils.getRequest(), paramsMap);
		String userid = (String) paramsMap.get("userid");
		try {
			this.getService().executeHQLUpdate(" update UserVO vo set vo.status = 0 where userid = ? ", new Object[]{userid});
			JsonObject result = new JsonObject();
			ResultJson resultJs = new ResultJson();
			resultJs.msg = "注销成功";
			result.add("result", resultJs.toJSON());
			sendJsonMessage(result.toString());
			
			ControlLogCategory logCategory = new ControlLogCategory();
			logCategory.setId(userid);
			logCategory.setName("");
			logCategorysArrayList.add(logCategory);
			
		} catch (Exception e) {
			sendErrMsg(e.getMessage());
		}
	}
	
	
	/**
	 * 
	 * @Title: userList
	 * @Description: 【用户列表】
	 * @param
	 * @return 设定文件
	 * @return String 返回类型
	 * @throws
	 */
	public void userListRequest(){
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(
				Struts2Utils.getRequest(), paramsMap);
		String username = (String) paramsMap.get("username");
		if( null != username){
			model.setUsername(username);
		}
		parsePageRequest();
		try {
			PageResponse pageResponse = new PageResponse();
			List list = service.getDataList(pageRequest.getIDisplayStart() , pageRequest.getIDisplayLength(), model, pageResponse, getService());
			pageResponse.setAaData(list);
			pageResponse.setSEcho(pageRequest.getSEcho());
			String jsonStr = JsonUtils.toJson(pageResponse, null, true, null, false);
			sendJsonMessage(jsonStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 * @Title: changePwd
	 * @Description: 【用户修改密码】
	 * @param
	 * @return 设定文件
	 * @return String 返回类型
	 * @throws
	 */
	public String changePwd() {
		JsonResult result = new JsonResult();
		try {
			Date accesstime = new Date();
			paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(
					Struts2Utils.getRequest(), paramsMap);
			String opercode = (String) paramsMap.get("userId");
			String oldpassword = (String) paramsMap.get("oldPwd");
			String newpassword = (String) paramsMap.get("newPwd");

			entityUserVO = this.getService().doFindByPk(UserVO.class, opercode);
			UserVO userVO = (UserVO) entityUserVO;
			// 判定旧密码是否正确
			if (!oldpassword.equalsIgnoreCase(userVO.getPasswd())) {
				throw new Exception("旧密码输入有误");
			}

			userVO.setPasswd(newpassword.toUpperCase());
			userVO.setLasteditor(userVO.getUserid());
			userVO.setLasttime(new Date());
			this.entityUserinfoVO = userVO;

			String oprClass = (voClass == null) ? "unknown" : voClass
					.getSimpleName().toLowerCase().replaceFirst("vo$", "");
			String userid = userVO.getUserid();
			String ip = IPUtil.getClientIP(Struts2Utils.getRequest());
			if (null == logClass) {
				logClass = LogAccessVO.class;
			}
			if (logClass == LogAccessVO.class) {
				logClass = LogAccessVO.class;

				logVO = this.getService().createAccesslogVO(userid, accesstime,
						oprClass, OperAction.UPDATE, ip, entityVO,
						entityUserinfoVO, OperState.SUCCESS);
				entityUserinfoVO = this.getService().doUpdate(voClass,
						entityUserinfoVO, logClass, logVO);
			}
			result.setStatus("OK");
			result.setMessage("修改成功");
			sendJsonMessage(result);
		} catch (Exception ex) {
			String errmsg = "操作失败，失败原因:" + ex.getMessage();
			logger.error(errmsg, ex);
			this.addErrorMessage(errmsg);
			result.setStatus("ERROR");
			result.setMessage(errmsg);
			try {
				sendJsonMessage(result);
			} catch (IOException e) {
				e.printStackTrace();
				logger.error("信息返回失败:{}", e);
			}
		}
		return null;
	}

	/**
	 * 查询列表信息
	 * 
	 * @return
	 */
	@Override
	public String list() {
		try {
			paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(
					Struts2Utils.getRequest(), paramsMap);
			this.setParamsMapToTargetObject(paramsMap, this.getEntityListVO());
			String _seq_userId = MapUtils.getString(paramsMap, "_seq_userId");
			String _sk_userName = MapUtils.getString(paramsMap, "_sk_userName");
			String _seq_status = MapUtils.getString(paramsMap, "_seq_status");

			StringBuffer sql = new StringBuffer(
					"select u.userid,u.username,u.orgid,u.worktitle,u.status,u.startdate,u.stopdate ")
					.append("from sys_user u where u.comid = ?");

			List<Object> params = new ArrayList<Object>();
			params.add(userVO.getComid());

			if (StringUtils.isNotBlank(_seq_userId)) {
				sql.append(" and u.userid = ? ");
				params.add(_seq_userId);
			}
			if (StringUtils.isNotBlank(_sk_userName)) {
				sql.append("  and u.username like concat('%',?,'%') ");
				params.add(_sk_userName);
			}
			if (StringUtils.isNotBlank(_seq_status)) {
				sql.append("  and u.status = ? ");
				params.add(_seq_status);
			}

			page = (Page) ObjectUtils.defaultIfNull(page, new Page());
			BeanUtils.copyProperties(page, this.getEntityListVO());
			page = this.getService().doQuery(page, sql.toString(),
					ExtUserVO.class, params.toArray());

			if (page.getTotalCount() > 0) {
				for (Iterator iter = page.getDatas().iterator(); iter.hasNext();) {
					ExtUserVO extUserVO = (ExtUserVO) iter.next();
					String userid = extUserVO.getUserid();
					String hql = "from UserinfoVO i where i.userid = ?";
					List<UserinfoVO> userinfolistVO = (List<UserinfoVO>) this
							.getService().doFindByHQL(hql,
									new Object[] { userid });
					if (userinfolistVO != null && userinfolistVO.size() > 0) {
						UserinfoVO userinfoVO = userinfolistVO.get(0);
						extUserVO.setSex(userinfoVO != null ? userinfoVO
								.getSex() : null);
						extUserVO.setMobileno(userinfoVO != null ? userinfoVO
								.getMobileno() : null);
						extUserVO.setConntel(userinfoVO != null ? userinfoVO
								.getConntel() : null);
					}
				}
			}
		} catch (Exception e) {
			log.error("操作失败,失败原因:" + e.getMessage(), e);
			this.addErrorMessage("操作失败,失败原因:" + e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}

	@Override
	public Object getEntityListVO() {
		if (entityListVO == null) {
			synchronized (UserAction.class) {
				this.entityListVO = new OperatorAndInfoListVO();
			}
		}
		return entityListVO;
	}

	/**
	 * 新UI框架下的用户选择页面
	 * 
	 * @return
	 * 
	 * @Copyright: Copyright (c) 2006
	 * @Company: Revenco Tech Ltd.
	 * @anthor chenminhui<chenminhui@revenco.com>
	 * @since 2014-9-25 下午05:34:16
	 * @version V1.0
	 */
	public String select2() {
		try {
			UserListVO listVO = new UserListVO();

			paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
			this.setParamsMapToTargetObject(paramsMap, listVO);
			listVO.set_seq_comid(userVO.getComid());
			page = this.getService().doQuery(UserVO.class, listVO);
		} catch (Exception ex) {
			this.addErrorMessage(ex.getMessage());
			ex.printStackTrace();
			return ERROR;
		}
		return SUCCESS;

	}
	

	/**
	 * 获取用户明细信息
	 * 
	 * @return
	 * 
	 * @Copyright: Copyright (c) 2006
	 * @Company: Revenco Tech Ltd.
	 * @anthor chenminhui<chenminhui@revenco.com>
	 * @since 2014-9-25 下午05:51:47
	 * @version V1.0
	 * @throws IOException
	 */
	public String getUserInfo() throws IOException {
		try {

			paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(
					Struts2Utils.getRequest(), paramsMap);

			Assert.hasText(MapUtils.getString(paramsMap, "_seq_userId",
					StringUtils.EMPTY), "用户编码不能为空");

			UserinfoListVO listVO = new UserinfoListVO();

			this.setParamsMapToTargetObject(paramsMap, listVO);
			page = this.getService().doQuery(UserinfoVO.class, listVO);

			if (page.getTotalCount() > 0) {
				UserinfoVO vo = (UserinfoVO) page.getDatas().get(0);
				sendJsonMessage(new JsonResult(SUCCESS, JsonUtils.toJson(vo)));
			} else {
				sendJsonMessage(new JsonResult(ERROR, "找不到用户("
						+ MapUtils.getString(paramsMap, "_seq_userId") + ")信息"));
			}
		} catch (Exception ex) {
			String errmsg = "查询失败，原因：" + ex.getMessage();
			log.error(errmsg, ex);

			sendJsonMessage(new JsonResult(ERROR, errmsg));
		}
		return null;
	}
	
	
	

	/**
	 * 新增用户---加载公司简称
	 */
	// public String LoadComInfoById(){
	// UserVO result = new UserVO();
	// try{
	// paramsMap =
	// PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(),
	// paramsMap);
	// String comid = (String)paramsMap.get("PK");
	// ComanyVO comVO = (ComanyVO) this.getService().doFindByPk(voClass, comid);
	// if(comVO == null){
	// // result.setMessage("公司简称不存在!");
	// sendJsonMessage("公司简称不存在！");
	// result.setStatus("ERROR");
	// sendJsonMessage(JsonUtils.toJson(result,null,true,null,false));
	// return null;
	// }
	// String comshortid = comVO.getComshortid();
	// result.setUserid(comshortid);
	// result.setStatus("OK");
	// sendJsonMessage(JsonUtils.toJson(result,null,true,null,false));
	// return null;
	// }catch(Exception ex){
	// ex.printStackTrace();
	// return null;
	// }
	//		
	// }
	public void setEntityUserinfoVO(Object entityUserinfoVO) {
		this.entityUserinfoVO = entityUserinfoVO;
	}

	public void setEntityUserVO(Object entityUserVO) {
		this.entityUserVO = entityUserVO;
	}
	
	public static void main(String args[]) {
		String md5 = MD5Encrypt.getMD5Password("zhe8002015");
		System.out.println(md5);
	}
	
	private boolean getLastTimeAddAction(Integer len, Integer index){
		boolean isLast = false;
		if(len - index == 1){
			isLast = true;
		}
		return isLast;
	}
	
	private void sendErrMsg(String msg) {
		JsonObject result = new JsonObject();
		ResultJson resultJs = new ResultJson();
		resultJs.msg = msg;
		result.add("result", resultJs.toJSON());
		try {
			sendJsonMessage(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public String getActionId() {
		return "1000000801";
	}
	
	@Override
	public ArrayList<ControlLogCategory> getProduct() {
		return logCategorysArrayList;
	}
	
	@Override
	public Object getModel() {
		if(model == null)
		{
			model = new getUserModel();
		}
		return model;
	}
}
